#! /bin/sh
#
### BEGIN INIT INFO
# Provides:          ovn-central
# Required-Start:    openvswitch-switch $remote_fs $syslog
# Required-Stop:     $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: OVN central components
# Description:       ovn-central provides the userspace daemons,
#                    utilities and databases for OVN that is run at a central
#                    location.
### END INIT INFO

test -x /usr/bin/ovn-northd  || exit 0
test -x /usr/share/openvswitch/scripts/ovn-ctl || exit 0

_SYSTEMCTL_SKIP_REDIRECT=yes
SYSTEMCTL_SKIP_REDIRECT=yes

. /usr/share/openvswitch/scripts/ovs-lib
if [ -e /etc/default/ovn-central ]; then
    . /etc/default/ovn-central
fi

start () {
    set /usr/share/openvswitch/scripts/ovn-ctl ${1-start_northd}
    set "$@" $OVN_CTL_OPTS
    "$@" || exit $?
}

stop_northd () {
    set /usr/share/openvswitch/scripts/ovn-ctl ${1-stop_northd}
    set "$@" $OVN_CTL_OPTS
    "$@" || exit $?
}

case $1 in
    start)
        start
        ;;
    stop)
        stop_northd
        ;;
    restart)
        start restart_northd
        ;;
    reload | force-reload)
        ;;
    status)
        /usr/share/openvswitch/scripts/ovn-ctl status_northd
        exit $?
        ;;
    *)
        echo "Usage: $0 {start|stop|reload|force-reload|restart|status}" >&2
        exit 1
        ;;
esac

exit 0
